home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 15 / macformat_15.iso / C de cerca / Codewarrior Lite / MacOS Support / Headers / ANSI Headers / fstream < prev    next >
Text File  |  1995-12-29  |  4KB  |  157 lines

  1. // fstream standard header
  2. #ifndef _FSTREAM_
  3. #define _FSTREAM_
  4. #include <istream>
  5. #include <ostream>
  6.  
  7. #if __MWERKS__
  8. #pragma options align=mac68k
  9.  
  10. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  11. #pragma import on
  12. #endif
  13. #endif
  14.  
  15.   // class filebuf
  16. struct _Filet;
  17. class filebuf : public streambuf {
  18. public:
  19.  filebuf(_Filet *_F = 0)
  20.   {_Init(_F); }
  21.  filebuf(ios::_Uninitialized)
  22.   : streambuf(ios::_Noinit) {}
  23.  virtual ~filebuf();
  24.  _Bool is_open() const
  25.   {return ((_File != 0)); }
  26.  filebuf *open(const char *, ios::openmode);
  27.  filebuf *open(const char *_N, ios::open_mode _M)
  28.   {return (open(_N, (ios::openmode)_M)); }
  29.  filebuf *close();
  30. protected:
  31.  virtual int overflow(int = EOF);
  32.  virtual int pbackfail(int = EOF);
  33.  virtual int underflow();
  34.  virtual int uflow();
  35.  virtual int xsgetn(char *, int);
  36.  virtual int xsputn(const char *, int);
  37.  virtual streampos seekoff(streamoff, ios::seekdir,
  38.   ios::openmode = (ios::openmode)(ios::in | ios::out));
  39.  virtual streampos seekpos(streampos,
  40.   ios::openmode = (ios::openmode)(ios::in | ios::out));
  41.  virtual streambuf *setbuf(char *, int);
  42.  virtual int sync();
  43.  _Filet *_Init(_Filet * = 0, _Bool = 0);
  44. private:
  45.  _Bool _Closef;
  46.  _Filet *_File;
  47.  };
  48.   // class ifstream
  49. class ifstream : public istream {
  50. public:
  51.  ifstream()
  52.   : ios(&_Fb), istream(&_Fb) {}
  53.  ifstream(const char *_S, openmode _M = in)
  54.   : ios(&_Fb), istream(&_Fb) {_Fb.open(_S, _M); }
  55.  virtual ~ifstream();
  56.  filebuf *rdbuf() const
  57.   {return ((filebuf *)&_Fb); }
  58.  _Bool is_open() const
  59.   {return (_Fb.is_open()); }
  60.  void open(const char *_S, openmode _M = in)
  61.   {if (_Fb.open(_S, _M) == 0)
  62.     setstate(failbit); }
  63.  void open(const char *_S, open_mode _M)
  64.   {open(_S, (openmode)_M); }
  65.  void close()
  66.   {if (_Fb.close() == 0)
  67.     setstate(failbit); }
  68. private:
  69.  filebuf _Fb;
  70.  };
  71.   // class ofstream
  72. class ofstream : public ostream {
  73. public:
  74.  ofstream()
  75.   : ios(&_Fb), ostream(&_Fb) {}
  76.  ofstream(const char *_S, openmode _M = out | trunc)
  77.   : ios(&_Fb), ostream(&_Fb) {_Fb.open(_S, _M); }
  78.  virtual ~ofstream();
  79.  filebuf *rdbuf() const
  80.   {return ((filebuf *)&_Fb); }
  81.  _Bool is_open() const
  82.   {return (_Fb.is_open()); }
  83.  void open(const char *_S, openmode _M = out | trunc)
  84.   {if (_Fb.open(_S, _M) == 0)
  85.     setstate(failbit); }
  86.  void open(const char *_S, open_mode _M)
  87.   {open(_S, (openmode)_M); }
  88.  void close()
  89.   {if (_Fb.close() == 0)
  90.     setstate(failbit); }
  91. private:
  92.  filebuf _Fb;
  93.  };
  94.   // class stdiobuf
  95. class stdiobuf : public filebuf {
  96. public:
  97.  stdiobuf(_Filet *_F)
  98.   : filebuf(_F), _Is_buffered(0) {}
  99.  virtual ~stdiobuf();
  100.  _Bool buffered() const
  101.   {return (_Is_buffered); }
  102.  void buffered(_Bool _F)
  103.   {_Is_buffered = _F; }
  104. private:
  105.  _Bool _Is_buffered;
  106.  };
  107.   // class istdiostream
  108. class istdiostream : public istream {
  109. public:
  110.  istdiostream(_Filet *_F)
  111.   : ios(&_Fb), istream(&_Fb), _Fb(_F) {}
  112.  virtual ~istdiostream();
  113.  stdiobuf *rdbuf() const
  114.   {return ((stdiobuf *)&_Fb); }
  115.  _Bool buffered() const
  116.   {return (_Fb.buffered()); }
  117.  void buffered(_Bool _F)
  118.   {_Fb.buffered(_F); }
  119. private:
  120.  stdiobuf _Fb;
  121.  };
  122.   // class ostdiostream
  123. class ostdiostream : public ostream {
  124. public:
  125.  ostdiostream(_Filet *_F)
  126.   : ios(&_Fb), ostream(&_Fb), _Fb(_F) {}
  127.  virtual ~ostdiostream();
  128.  stdiobuf *rdbuf() const
  129.   {return ((stdiobuf *)&_Fb); }
  130.  _Bool buffered() const
  131.   {return (_Fb.buffered()); }
  132.  void buffered(_Bool _F)
  133.   {_Fb.buffered(_F); }
  134. private:
  135.  stdiobuf _Fb;
  136.  };
  137.  
  138. #if __MWERKS__
  139. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  140. #pragma import reset
  141. #endif
  142.  
  143. #pragma options align=reset
  144. #endif
  145.  
  146. #endif
  147.  
  148. /*
  149.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  150.  * Consult your license regarding permissions and restrictions.
  151.  */
  152.  
  153. /* Change log:
  154.  *94Oct03 Version received from PlumHall
  155.  *94Oct07 Inserted MW changes.
  156.  */
  157.